﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.IO;
using FSS;

public class GlobalConfigMgr : Singleton<GlobalConfigMgr>
{
    GlobalConfig mConfig = null;

    public IEnumerator LoadFromFile(string filename)
    {
        WWW www = new WWW(filename);
        yield return www;
        System.IO.StringReader stringReader = new System.IO.StringReader(www.text); ;
        string strContent = stringReader.ReadToEnd();
        mConfig = JsonUtility.FromJson<GlobalConfig>(strContent);
    }

    public void SaveToFile()
    {
        ConfigFilenames currentConfigFiles = ConfigFilesConfigMgr.Instance.mConfig.SchemaFiles[ConfigFilesConfigMgr.Instance.mConfig.SchemeSelected];
        string filename = ConfigManager.Instance.WritableJsonConfigPath +
            currentConfigFiles.BuildingTypesConfigFile;
        Debug.Log("GlobalConfigMgr SaveToFile:" + filename);
        StreamWriter sw;
        FileInfo fi = new FileInfo(filename);
        string strJsonText = mConfig.ToJsonStr();
        sw = fi.CreateText();
        sw.Write(strJsonText);
        sw.Close();
        sw.Dispose();
    }
}

[Serializable]
public class GlobalConfig : JsonConfigBase {
    public bool ShowDebugMsg;
}
